version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.VIII OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
merge				m:1 regno year using "$project_data\Name_counts_byyear.dta"
drop				if _merge==2
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* DEFINE TREATMENT VARIABLE */

g				logtaxpaid=log(TaxPaid)
g				namefreq_t1=name_count_v3 if year==2012
bys			regno:egen namefreq_t2=min(namefreq_t1)
g				name_freq_t3=namefreq_t2
replace		name_freq_t3=name_count_v3 if name_freq_t3==.
bys			regno:egen namefreq=min(name_freq_t3)
replace		namefreq=namefreq*4
qui			tab year, g(ydum)
g				after=year>=2012

/* COMPLETE PANEL */

local			j=1
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=1
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCE PANEL */

bys			regno:g nreturns=_N
keep			if nreturns==10
local			j=2
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=1
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

*--------------------------------
* PLACEBO REGRESSION 
*--------------------------------

use			"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
merge			m:1 regno year using "$project_data\Name_counts_byyear.dta"
drop			if _merge==2
g				logtaxpaid=log(TaxPaid)
g				namefreq_t1=name_count_v3 if year==2012
bys			regno:egen namefreq_t2=min(namefreq_t1)
g				name_freq_t3=namefreq_t2
replace		name_freq_t3=name_count_v3 if name_freq_t3==.
bys			regno:egen namefreq=min(name_freq_t3)
replace		namefreq=namefreq*4
drop			if year>=2012
g				after=year>=2010

/* COMPLETE PANEL */

local			j=1
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=4
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCE PANEL */

bys			regno:g nreturns=_N
keep			if nreturns==6
local			j=2
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=4
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* FORMATTING THE TABLE */

svmat 		table
keep			tab*
drop			table9-table12
keep			if _n<=6
g				c11=""
replace		c11="treat $\times$ after" in 1
replace		c11="Observations" in 3
replace		c11="treat $\times$ after" in 4
replace		c11="Observations" in 6

forvalues 	c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
foreach		r in 2 5 {
forvalues	c=1/8 {
replace		c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues	c=1/8 {
replace		c`c'=string(table`c',"%15.0fc") in 3
replace		c`c'=string(table`c',"%15.0fc") in 6
}
forvalues	s=1/15 {
g				s`s'="&"
}
g				l="\\"
foreach		r in 2 3 5 6 {
replace		l="\\\\" in `r'
}
order			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l
browse		c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l


